Ext.namespace("admin.systemManage");

admin.systemManage.fileClean = function(panelId, title, iconClz){

	loadTmpNum();

	var fileForm = new Ext.form.FormPanel({
		defaults : {
			width : 100,
			readOnly : true
		},
		labelWidth : 120,
		frame : true,
		items : [{
			xtype : "numberfield",
			iconCls : "clean",
			fieldLabel : "临时文件数量"
		}, {
			xtype : "numberfield",
			iconCls : "clean",
			fieldLabel : "未被使用的附件数量"
		}]
	});

	var optBar = [{
		text : "清理",
		iconCls : "clean",
		handler : function(){
			ajaxRequest({
				url : "admin/system/cleanTmpFile",
				callback : function(){
					loadTmpNum();
				}
			})
		}
	}]

	return new Ext.Panel({
		id : panelId,
		title : title,
		iconCls : iconClz,
		closable : true,
		items : fileForm,
		tbar : genToolBar(optBar, null, panelId)
	});

	function loadTmpNum(){
		ajaxRequest({
			url : "admin/system/countTmpFile",
			callback : function(json){
				var attachment = json.data.attachment;
				var tmpFile = json.data.tmpFile;
				var children = fileForm.findByType("numberfield");
				children[0].setValue(tmpFile);
				children[1].setValue(attachment);
			}
		});
	}
}

registerModule("admin.systemManage.fileClean", admin.systemManage.fileClean);